package cn.itcast.bos.web.action.base;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.base.Courier;
import cn.itcast.bos.service.base.CourierService;
import cn.itcast.bos.web.action.common.BaseAction;

@Namespace("/")
@ParentPackage("json-default")
@Controller
@Scope("prototype")
public class CourierAction extends BaseAction<Courier> {

	@Autowired
	private CourierService courierService;

	//查询未绑定定区的快递员
	@Action(value = "courier_findNoAssociation", results = { @Result(name = "success", type = "json") })
	public String findNoAssociationFixedArea(){
		List<Courier> couriers = courierService.findNoAssociation();
		ActionContext.getContext().getValueStack().push(couriers);
		return SUCCESS;
	}
	
	// 添加快递员
	@Action(value = "courier_save", results = {
			@Result(name = "success", location = "./pages/base/courier.html", type = "redirect") })
	public String save() {

		courierService.save(model);
		System.out.println("添加成功");
		return SUCCESS;
	}

	// 分页查询快递员
	@Action(value = "courier_pageQuery", results = { @Result(name = "success", type = "json") })
	public String pageQuery() {

		Pageable pageable = new PageRequest(page - 1, rows);

		Page<Courier> pageData = courierService.findPageData(model, pageable);
		pushPageDataToValueStack(pageData);
		return SUCCESS;
	}
	
	private String ids;
	
	public void setIds(String ids) {
		this.ids = ids;
	}

	//批量作废
	@Action(value="courier_delBatch",results={@Result(name="success",location="./pages/base/courier.html",type="redirect")})
	public String delBatch() {
		String[] idArray = ids.split(",");
		courierService.delBatch(idArray);
		return SUCCESS;
	}
}
